package com.code.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.code.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("user")
public class TestController {

    @PostMapping("login")
    public Result login(){
        Map<String, Object> result = new HashMap<>();
        String id = String.valueOf(UUID.randomUUID());
        StpUtil.login(id);
        result.put("token", StpUtil.getTokenValue());
        return Result.success("",result);
    }
    @PostMapping("logout")
    public Result logout(){
        StpUtil.logout();
        return Result.success();
    }
    @GetMapping("getMeInfo")
    public Result getMeInfo(){
        Map<String, Object> result = new HashMap<>();
        result.put("roles", Arrays.asList("admin"));
        result.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80");
        return Result.success(result);
    }
}
